<%@ page import="com.hyd.tweet.twitter.TwitterUtils" %>
<%@ page import="twitter4j.Query" %>
<%@ page import="twitter4j.QueryResult" %>
<%@ page import="twitter4j.Status" %>
<%@ page import="twitter4j.Twitter" %>
<%--
  test twitter4j search 
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String q = request.getParameter("q");
    if (q == null) {
        q = "";
    }

    QueryResult result = null;
    if (!q.equals("")) {
        Query query = new Query(q);
        query.setResultType("recent");

        Twitter twitter = TwitterUtils.createAnonymousTwitter();
        result = twitter.search(query);
    }
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>twitter search</title>
</head>
<body>

<form action="">
    <input type="text" name="q" value="<%=q%>">
    <input type="submit" value="search">
</form>

<%
    if (result != null) {
        for (Status tweet : result.getTweets()) {
            %><p><%=tweet.getCreatedAt()%> <%="@" + tweet.getUser() + " - " + tweet.getText()%></p><%
        }
    }
%>

<p>
    
</p>
</body>
</html>